package com.huanzhidadi.single.completablefuture;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * 不会返回结果，只是执行线程任务
 * CompletableFuture<Void> runAsync(Runnable runnable, Executor executor)
 */
public class RunAsyncTest {
    public static void main(String[] args) {
        System.out.println("主程序：" + Thread.currentThread().getName());
        ExecutorService executorService = Executors.newFixedThreadPool(100);
        CompletableFuture.runAsync(() -> {
            System.out.println("子程序：" + Thread.currentThread().getName());
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("子程序运行结束：" + Thread.currentThread().getName());
        }, executorService);
        System.out.println("主程序运行结束");
        executorService.shutdown();
    }
}
